"""
# -*- coding: utf-8 -*-
# @Time    : 2023/6/13 21:48
# @Author  : 王摇摆
# @FileName: multilabel.py
# @Software: PyCharm
# @Blog    ：https://blog.csdn.net/weixin_44943389?type=blog
"""
import numpy as np
# from ..Dataset.Data import y_train # 这里的相对导入是不对的，因为该文件在文件夹中，被视作为顶级包
from sklearn import metrics
from sklearn.linear_model import LogisticRegression

from Dataset.Data import y_train, X_train, X_test, y_test  # 这样才是正确的，在当前的目录结构中，只能使用绝对导入
from sklearn.multiclass import OneVsRestClassifier

y_train_multilabel = np.c_[y_train % 2 == 0, y_train <= 4]  # 标签制作

ova_ml = OneVsRestClassifier(LogisticRegression(solver='lbfgs', max_iter=800))
print('模型已构造成功')
ova_ml.fit(X_train, y_train_multilabel)
print('模型已学习完毕')

print('\n===============正在输出训练结果======================')
print('OvA LR - Accuracy (Train): %.4g' % metrics.accuracy_score(y_train_multilabel, ova_ml.predict(X_train)))
# print("OvA LR - Accuracy (Test): %.4g" % metrics.accuracy_score(y_train_multilabel, ova_ml.predict(X_test)))


print( y_test[:1] )
print( ova_ml.predict(X_test[:1,:]) )
